<?php
namespace app\admin\models;
use think\Model;

class Goods extends Model
{	public $imageFile;
    protected $aid = 'goods_id';
    protected $table = 'lsq_goods';
     protected $resultSetType = 'collection';
     public static function init()
    {
      
    }
public function upload()
    {
        if ($this->validate()) {
			$filename = 'cover_'.uniqid();
			$path = 'data/attachment/photo/'.date('Ymd',time()).'/';
			if(!file_exists($path)){
				$this->createDir($path);
			}
            $this->imageFile->saveAs($path.$filename . '.' . $this->imageFile->extension);
            return $path.$filename.'.'.$this->imageFile->extension;
        } else {
            return false;
        }
    }

    public function createDir($str)
	{
		$arr= explode('/', $str);
		if(!empty($arr))
		{
			$path= '';
			foreach($arr as $k=>$v)
			{
				$path.= $v.'/';
				if(!file_exists($path)) {
					mkdir($path, 0777);
					chmod($path, 0777);
				}
			}
		}
	}



   
   
}